/*
 * @Author: xuwejie 1529315455@qq.com
 * @Date: 2023-08-28 14:39:14
 * @LastEditors: xuwejie 1529315455@qq.com
 * @LastEditTime: 2023-11-17 15:06:04
 * @FilePath: \v9\src\store\modules\app.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Cookies from "js-cookie";

const state = {
  sidebar: {
    opened: Cookies.get("sidebarStatus")
      ? !!+Cookies.get("sidebarStatus")
      : false,
    withoutAnimation: false
  },
  classOn: false,
  device: "desktop",
  two_level_open: false, //二级菜单缩放起时，侧边栏右上角的展开符号，
  // 当前菜单的id
  ids: {
    first_id: "",
    second_id: ""
  },
  // 权限
  permission: {},
  //路由keep-刷新
  storagekeep: false,
  // 个性化侧边栏是否展示
  showSideBar: false,
  isChangeSideBar: Cookies.get("isChangeSideBar") == 1 ? false : true,  //  是否切换左侧导航条模式
};

const mutations = {
  SET_ISCHANGESIDEBAR: (state, bool) => {
    state.isChangeSideBar = bool
    Cookies.set('isChangeSideBar', bool ? 0 : 1)
  },
  STORAGECHANGE: (state, type) => {
    state.storagekeep = type;
  },
  TOGGLE_SIDEBAR: state => {
    state.sidebar.opened = !state.sidebar.opened;
    state.sidebar.withoutAnimation = false;
    if (state.sidebar.opened) {
      Cookies.set("sidebarStatus", 1);
    } else {
      Cookies.set("sidebarStatus", 0);
    }
  },
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    Cookies.set("sidebarStatus", 0);
    state.sidebar.opened = false;
    state.sidebar.withoutAnimation = withoutAnimation;
  },
  TOGGLE_DEVICE: (state, device) => {
    state.device = device;
  },
  CLASS_ON: (state, data) => {
    state.classOn = data;
  },
  TWO_LEVEL_OPEN: (state, data) => {
    state.two_level_open = data;
  },
  SET_IDS: (state, data) => {
    state.ids = data;
  },
  SET_PERMISSON: (state, data) => {
    state.permission = data;
  },
  SET_SHOWSIDEBAR: (state, data) => {
    state.showSideBar = data;
  }
};

const actions = {
  toggleSideBar({ commit }) {
    commit("TOGGLE_SIDEBAR");
  },
  closeSideBar({ commit }, { withoutAnimation }) {
    commit("CLOSE_SIDEBAR", withoutAnimation);
  },
  toggleDevice({ commit }, device) {
    commit("TOGGLE_DEVICE", device);
  },
  setIds({ commit }, ids) {
    commit("SET_IDS", ids);
  },
  set_permisson({ commit }, permission) {
    commit("SET_PERMISSON", permission);
  },
  set_showSidebar({ commit }, permission) {
    commit("SET_SHOWSIDEBAR", permission);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
